<?php
/////////////////////////////////////////////////////////////////////////////
// 
//
// workflow_system 
//
// workflow_copyright
// 
/////////////////////////////////////////////////////////////////////////////

/**
 * FILE_NAME : vote.class.php   FILE_PATH : E:\www\\classes\application\vote.class.php
 * 投票管理操作类
 *
 * @copyright Copyright (c) 2007 - 2007 www.shopnc.net 
 * @author workflow Develop Team 
 * @package 
 * @subpackage 
 * @version Tue Feb 12 15:12:34 CST 2008
 */

class VoteClass extends FrameWork {
	/**
	 * 投票主题列表
	 * @author  
	 * @param  
	 * @return bool
	 */
	function listVote($condition,&$obj_page){
		$conditionstr = $this->_conditionSearch($condition);
		$vote_array = $GLOBALS['db']->GetList($conditionstr, $obj_page, "vote");
		return $vote_array;
	}
	
	/**
	 * 新增投票信息
	 * @author     
	 * @param  
	 * @return bool
	 */
	function addVote($input_param){
		$value_array = array();
		$value_array['vote_title'] = trim($input_param['txttitle']);/*主题*/
		$value_array['vote_refresh'] = $input_param['txtrefresh'];/*重复投票*/
		$value_array['vote_member'] = $input_param['txtmember'];/*投票范围*/
		$value_array['vote_content'] = $input_param['txtcontent'];/*投票选项*/
		$value_array['vote_check'] = $input_param['txtcheck'];/*是否多选*/
		$value_array['vote_sort'] = $input_param['txtsort'];/*序号*/
		$value_array['vote_date'] = $input_param['txtdate'];/*添加时间*/
		$insert_rs = $GLOBALS['db']->InsertRow($value_array, 'vote', 'vote_id');
		return $insert_rs;
	}
	
	/**
	 * 取投票记录
	 * @author 
	 * @param  
	 * @return array
	 */
	function getOneVote($id){
		if (intval($id)>0) {
			return $GLOBALS['db']->GetOneRow($id,'vote','vote_id');
		}else {
			return false;
		}
	}
	
	/**
	 * 构造检索条件
	 * @author     
	 * @param  
	 * @return bool
	 */
	function _conditionSearch($condition){
		
		$condition_str = '';
		
		/*主题ID*/
		if ($condition['id'] != '' && $condition['id'] != '0') {
			$condition_str .= " and vote_id = '" . $condition['id'] . "'";
		}
		
		/*时间*/
		if ($condition['date'] != '') {
			$condition_str .= " and vote_date = '" . $condition['date'] . "'";
		}
		
		/*显示时间段*/
		if ($condition['show_date'] != '') {
			$condition_str .= " and vote_start_date <= '" . $condition['show_date'] . "' and '" . $condition['show_date'] . "' <= vote_end_date";
		}
		
		/*排序*/
		if ($condition['order'] == 'asc') {
			$condition_str .= " order by vote_id asc";
		}elseif ($condition['order'] == 'desc'){
			$condition_str .= " order by vote_id desc";
		}elseif ($condition['order'] == 'sort'){
			$condition_str .= " order by vote_sort asc";
		}
		
		return $condition_str;
	}

	/**
	 * 修改投票信息
	 * @author     
	 * @param  
	 * @return bool
	 */
	function modiVote($input_param){
		$value_array = array();		
		foreach ($input_param as $k => $v){
			if($k !="vote_id"){
				$value_array[$k] = $v;
			}
		}
		$insert_rs = $GLOBALS['db']->UpdateRow($input_param['vote_id'],$value_array, 'vote', 'vote_id');
		return $insert_rs;
	}
	
	/**
	 * 删除投票
	 * @author     
	 * @param  
	 * @return bool
	 */
	function delVote($vote_id){
		if (intval($vote_id) > 0){
			return $GLOBALS['db']->DelRow(intval($vote_id),'vote','vote_id');
		}else {
			return false;
		}
	}
	
	/**
	 * 构造检索条件
	 * @author     
	 * @param  
	 * @return bool
	 */
	function _conditionShowSearch($condition){
		
		$condition_str = '';
		/*前台显示表的构造语句*/
		/*前台显示位置*/
		if ($condition['show_name'] != '') {
			$condition_str .= " and show_name = '". $condition['show_name'] ."'";
		}
		/*主题ID*/
		if ($condition['show_id'] != '') {
			$condition_str .= " and vote_id = '". $condition['show_id'] ."'";
		}
		
		/*序号*/
		if ($condition['sort'] != '') {
			$condition_str .= " order by show_sort asc";
		}
		
		/*前台显示排序*/
		if ($condition['show_order'] == 'asc') {
			$condition_str .= " order by vote_show_id asc";
		}elseif ($condition['show_order'] == 'desc'){
			$condition_str .= " order by vote_show_id desc";
		}
		
		return $condition_str;
	}
}
?>